
#ifdef __cplusplus
 extern "C" {
#endif

#ifndef __INNERBUSRINGBUFF_H
#define __INNERBUSRINGBUFF_H


#define  RINGBUFF_USE_MUTEX   0

#if RINGBUFF_USE_MUTEX
#define  MUTEX_TIMEOUT   1000     
#define  MUTEX_T         TX_MUTEX 
#endif

typedef struct ringbuff 
{
	uint8_t* buffer;  
	uint32_t len;      
	__IO uint32_t in;       
	__IO uint32_t out;      
#if RINGBUFF_USE_MUTEX
	MUTEX_T *mutex;      
#endif
}Ring_t;

typedef enum err
{
    ERR_NONE = 0u,

    ERR_MEM_CREATE_ISR ,
    ERR_MEM_FULL ,
    ERR_MEM_INVALID_P_ADDR ,
    ERR_MEM_INVALID_BLKS ,
    ERR_MEM_INVALID_PART ,
    ERR_MEM_INVALID_P_BLK ,
    ERR_MEM_INVALID_P_MEM ,
    ERR_MEM_INVALID_P_DATA ,
    ERR_MEM_INVALID_SIZE ,
    ERR_MEM_NO_FREE_BLKS ,

    ERR_RING_INVALID_P_ADDR ,
    ERR_RING_INVALID_SIZE ,
    ERR_RING_INVALID_P_MEM ,
    ERR_RING_INVALID_MUTEX ,

    ERR_LIST_NO_ENTER,

    ERR_REGISTER_NO_ADD,
    ERR_REGISTER_ADD_EXIST,

 
} ERR_E;

#if RINGBUFF_USE_MUTEX
static ERR_E RingBuff_Create_Mutex(MUTEX_T *mutex);
static ERR_E RingBuff_Deleta_Mutex(MUTEX_T *mutex);

static ERR_E RingBuff_Request_Mutex(MUTEX_T *mutex);
static ERR_E RingBuff_Release_Mutex(MUTEX_T *mutex);
#endif
ERR_E RingBuff_Create(Ring_t *rb, uint8_t *buffer, uint32_t len);
ERR_E RingBuff_Delete(Ring_t *rb);
ERR_E RingBuff_Clear(Ring_t *rb);
uint32_t RingBuff_Write(Ring_t *rb,const uint8_t* wbuff,uint32_t len, ERR_E *err);
uint32_t RingBuff_Read(Ring_t *rb,uint8_t* rbuff, uint32_t len, ERR_E *err);
uint32_t RingBuff_GetLen(Ring_t *rb);
#endif 

#ifdef __cplusplus
}
#endif














